<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product media data template
 *
 * @see Mage_Catalog_Block_Product_View_Media
 */
?>
<?php
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
	$setting = Mage::helper('wishcartsettings');
	$viewmode = $setting->getImageProduct_Viewmode();
	$maxItem = 4;
    $isMobile = $setting->checkMobilePhp();
    if($isMobile == 'true'){$maxItem=4;}
?>
<?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
	<?php if ($viewmode == 'cloudzoom'): ?>
	<p class="product-image cloudzoom">
		<?php
			$_img = $this->helper('catalog/image')->init($_product, 'image');
			$_img2 = clone $_img;
			$config = "zoomWidth: ".min($setting->getImageProduct_CloudZoomWidth(500), $_img->getOriginalWidth()).",";
			$config .= "zoomHeight: ".min($setting->getImageProduct_CloudZoomHeight(500), $_img->getOriginalHeight()).",";
			$config .= 'adjustX: 10, adjustY:-4';
			if($_img->getOriginalWidth() >= 430)
				$w	=	430;
			else
				$w  =	$_img->getOriginalWidth();
			$ratio = $w / $_img->getOriginalWidth();
			$h = $ratio * $_img->getOriginalHeight();
		?>
		<a class="cloud-zoom" id="image_zoom" rel="<?php echo $config ?>" href="<?php echo $_img ?>" >
			<img src="<?php echo $_img->resize($w, $h); ?>" alt='' title="<?php echo $this->escapeHtml($this->getImageLabel());?>" />
		</a>
		<a id="zoom-btn" rel="lightbox[em_lightbox]" href="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>" title="<?php echo $this->escapeHtml($this->getImageLabel());?>">Zoom</a>
	</p>
	<?php elseif ($viewmode == 'lightbox'): ?>
	<p class="product-image lightbox">
		<a rel="lightbox[em_lightbox]"  href="<?php echo $this->helper('catalog/image')->init($_product, 'image'); ?>"  title="<?php echo $this->escapeHtml($this->getImageLabel())?>">
		<?php
			$w = 380;
			$h = 380;
			$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image')->resize($w, $h).'" alt="'.$this->escapeHtml($this->getImageLabel()).'" title="'.$this->escapeHtml($this->getImageLabel()).'" />';
			echo $_helper->productAttribute($_product, $_img, 'image');
		?>
		</a>
	</p>
	<?php else: ?>
	<p class="product-image product-image-zoom" style="width:430px;height:430px">
		<?php
			$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->escapeHtml($this->getImageLabel()).'" title="'.$this->escapeHtml($this->getImageLabel()).'" />';
			echo $_helper->productAttribute($_product, $_img, 'image');
		?>
	</p>
	<p class="zoom-notice" id="track_hint"><?php echo $this->__('Double click on above image to view full picture') ?></p>
	<div class="zoom">
		<img id="zoom_out" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif') ?>" alt="<?php echo $this->__('Zoom Out') ?>" title="<?php echo $this->__('Zoom Out') ?>" class="btn-zoom-out" />
		<div id="track">
			<div id="handle"></div>
		</div>
		<img id="zoom_in" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif') ?>" alt="<?php echo $this->__('Zoom In') ?>" title="<?php echo $this->__('Zoom In') ?>" class="btn-zoom-in" />
	</div>
	<script type="text/javascript">
	//<![CDATA[
	    Event.observe(window, 'load', function() {
	        product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
	    });
	//]]>
	</script>
	<?php endif ?>
<?php else: ?>
<p class="product-image product-image-simple">
    <?php
        $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(380).'" alt="'.$this->escapeHtml($this->getImageLabel()).'" title="'.$this->escapeHtml($this->getImageLabel()).'" />';
        echo $_helper->productAttribute($_product, $_img, 'image');
    ?>
</p>
<?php endif; ?>
<?php $count = count($this->getGalleryImages()); ?>
<?php if ($count > 0): ?>
<div class="more-views" id="moreview_products">
    <h2><?php echo $this->__('More Views') ?></h2>
    <ul class="slides">
    <?php $i=1; foreach ($this->getGalleryImages() as $_image): ?>
        <li class="item">
			<?php $_img = $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>
			
			<?php if ($viewmode == 'cloudzoom'): ?>
			<?php
				$_img_thumb = (string)$_img->resize(null);
				if($_img->getOriginalWidth() >= 430)
					$mv_w	=	430;
				else
					$mv_w	=	$_img->getOriginalWidth();
				$ratio = $mv_w / $_img->getOriginalWidth();
				$mv_h = $ratio * $_img->getOriginalHeight();
				$_img_thumb = (string)$_img->resize(110,110);
				$_img_small = (string)$this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize($mv_w,$mv_h);
				$_img_big = (string)$this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile());
			?>
				<a class="cloud-zoom-gallery" rel="
					useZoom:'image_zoom',
					smallImage:'<?php echo $_img_small ?>',
					adjustX:10, adjustY:-4" onclick="return false" href="<?php echo $_img_big ?>">
					<img src="<?php echo $_img_thumb ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" />
				</a>
				<a class="no-display" href="<?php echo $_img_big ?>" rel="lightbox[em_lightbox]">lightbox moreview</a>

			<?php elseif ($viewmode == 'lightbox'): ?>
				<?php $_img_thumb = (string)$_img->resize(110, 110); ?>
				<a rel="lightbox[em_lightbox]"  href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>"  title="<?php echo $this->escapeHtml($_image->getLabel()) ?>">
					<img src="<?php echo $_img_thumb; ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" />
				</a>			

			<?php else: ?>
				<?php $_img_thumb = (string)$_img->resize(110, 110); ?>
				<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=380,height=380,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->escapeHtml($_image->getLabel()) ?>">
					<img src="<?php echo $_img_thumb; ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" />
				</a>
			<?php endif ?>
        </li>
        <?php $i++; ?>
    <?php endforeach; ?>
    </ul>
</div>
<?php //if($count > $maxItem): ?>
	<script type="text/javascript">
		jQuery(window).load(function() {
			jQuery('#moreview_products').csslider({
				move : 1,
				direction : 'horizontal'
			});
		});
	</script>
<?php //endif ?>
<script type="text/javascript">
jQuery('.cloud-zoom-gallery').click(function () {
	jQuery('#zoom-btn').attr('href', this.href);
});
</script>
<?php endif; ?>
